package org.graduates.webapp.actions.course;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.HomeworkAssignments;
import org.projects.graduates.domain.TimeTable;

/**
 * 布置作业
 * 
 * @author Administrator
 * 
 */
@Action(results = { @Result(name = "success", type = "redirect", location = "teachings.action", params = { "tId", "${ha.timeTable.course.id}" }) })
public class CommitHomeworkAssignmentAction extends BaseAction {

	private static final long serialVersionUID = 4831039327265377021L;

	private long tid = 0L;

	private HomeworkAssignments ha;

	public String execute() {
		if (null == ha || 0L == tid || StringUtils.isEmpty(ha.getContent())) {
			return INPUT;
		}
		TimeTable tt = TimeTable.get(TimeTable.class, tid);

		if (null == tt) {
			return INPUT;
		}
		ha.setTimeTable(tt);
		ha.setTime(new Date());
		this.gradApplication.save(ha);
		return SUCCESS;
	}

	public HomeworkAssignments getHa() {
		return ha;
	}

	public void setHa(HomeworkAssignments ha) {
		this.ha = ha;
	}

	public long getTid() {
		return tid;
	}

	public void setTid(long tid) {
		this.tid = tid;
	}

}
